package com.jeecg.listener;

import java.io.File;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import com.jeecg.utils.ClassPathScanner;
import com.jeecg.utils.XmlBean;
import com.jeecg.utils.XmlPraser;

public class LoadXMLListener implements ServletContextListener {

	public void contextDestroyed(ServletContextEvent arg0) {

	}

	public void contextInitialized(ServletContextEvent arg0) {

		String contextConfigLocation = arg0.getServletContext()
				.getInitParameter("contextConfigLocation");

		File file = new File(Thread.currentThread().getContextClassLoader()
				.getResource(contextConfigLocation).getPath());

		XmlBean xmlBean = XmlPraser.XmlLoader(file);

		List<Map> map = ClassPathScanner.scannerClassBeans(xmlBean);

		arg0.getServletContext().setAttribute("loadPath", map);
		arg0.getServletContext().setAttribute("xmlBean", xmlBean);
	}

}
